package com.csust.cg.mongodb.common;

/**
 * @author chenguang
 */

public enum FilterConstant {
    /**
     * values equal to a specified value.
     */
    EQ("eq"),

    /**
     * values not equal to a specified value.
     */
    NE("ne"),

    /**
     * values greater than a specified value.
     */
    GT("gt"),

    /**
     * values greater than or equal to a specified value.
     */
    GTE("gte"),

    /**
     * values less than a specified value.
     */
    LT("lt"),

    /**
     * values less than or equal to a specified value.
     */
    LTE("lte"),

    /**
     * any of the values specified in an array.
     */
    IN("in"),

    /**
     * none of the values specified in an array.
     */
    NIN("nin"),

    /**
     * documents with the conditions of all the filters. This operator joins filters with a logical AND.
     */
    AND("and"),

    /**
     * documents with the conditions of either filter. This operator joins filters with a logical OR.
     */
    OR("or");

    private final String filterName;

    FilterConstant(String filterName) {
        this.filterName = filterName;
    }

    /**
     * 根据条件的名称，返回条件的枚举实例。
     *
     * @param filterName 条件名称
     */
    public static FilterConstant fromFilterName(String filterName) {
        for (FilterConstant filter : FilterConstant.values()) {
            if (filter.getFilterName().equals(filterName)) {
                return filter;
            }
        }
        return null;
    }

    public String getFilterName() {
        return this.filterName;
    }
}
